package 上机练习;

import java.math.BigDecimal;
import java.util.Scanner;

public class Practice03 {
	/*
	 * 查询商品价格.
	 */
	public static void main(String[] args) {
		double discount = 0.8;
		double total = 0.0D;
		double payment = 0.0D;
		int amount = 0;

		int goodsNO1 = 1;
		String goodsName1 = "苹果";
		double goodsPrice1 = 8000.00d;
		// int quantity1 = 5;
		// double subTotal=goodsPrice1*quantity1;

		int goodsNO2 = 2;
		String goodsName2 = "华为";
		double goodsPrice2 = 6000.00d;
		// int quantity2 = 9;

		int goodsNO3 = 3;
		String goodsName3 = "VIVO ";
		double goodsPrice3 = 2000.00d;
		// int quantity3 = 19;

		System.out.println("Myshopping购物管理系统>购物结算");
		System.out.println("*************************");
		System.out.println("商品编号\t商品名称\t商品价格");
		String line1 = String.format("%d\t%s\t%.2f", goodsNO1, goodsName1, goodsPrice1);
		String line2 = String.format("%d\t%s\t%.2f", goodsNO2, goodsName2, goodsPrice2);
		String line3 = String.format("%d\t%s\t%.2f", goodsNO3, goodsName3, goodsPrice3);
		System.out.println("***********************************");
		System.out.println(line1);
		System.out.println(line2);
		System.out.println(line3);
		Scanner input = new Scanner(System.in);
		String reply = "y";
		while ("y".equals(reply)) {
			System.out.println("请输入商品编号:");
			int productId = input.nextInt();

			System.out.print("请输入购买数量：");
			amount = input.nextInt();

			switch (productId) {
			case 1:
				System.out
						.println(goodsName1 + "\t¥" + goodsPrice1 + "\t数量" + amount + "\t合计¥" + (goodsPrice1 * amount));
				total += goodsPrice1 * amount;

				break;
			case 2:
				System.out
						.println(goodsName2 + "\t¥" + goodsPrice2 + "\t数量" + amount + "\t合计¥" + (goodsPrice2 * amount));
				total += goodsPrice2 * amount;

				break;
			case 3:
				System.out
						.println(goodsName3 + "\t¥" + goodsPrice3 + "\t数量" + amount + "\t合计¥" + (goodsPrice3 * amount));
				total += goodsPrice3 * amount;

				break;

			default:
				System.out.println("你没有查询到满足信息！！");
				break;
			}
			System.out.print("是否想要继续查询呢？(y/n):");
			reply = input.next();

		}
		double money = total * discount; // 折扣后的商品总价

		BigDecimal bd = new BigDecimal(money);
		money = bd.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();

		System.out.println("折扣：" + discount);
		System.out.println("应付金额：" + money);
		System.out.print("实付金额：");
		payment = input.nextDouble();
		double remain = payment - money;
		bd = new BigDecimal(remain);
		remain = bd.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
		System.out.println("找零：" + remain);

		System.out.println("谢谢使用本程序！！！");

	}

}
